package org.softmed.rest.generation.fields;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GenerationConfig {

	Map<String, String> classAlias = new HashMap<String, String>();
	List<String> omitClasses = new ArrayList<String>();
	Map<String, FieldNameList> omitFields = new HashMap<String, FieldNameList>();
	Map<String, AliasFields> aliasFields = new HashMap<String, AliasFields>();
	Map<String, FieldNameList> attributeFields = new HashMap<String, FieldNameList>();

	public GenerationConfig() {
	}

	
//	public void omitClass(String className){
//		omitClasses.add(className);
//	}
	
	public void omitClass(Class type){
		omitClasses.add(type.getCanonicalName());
	}
	
	
	public String getAlias(Class type) {
		String alias = classAlias.get(type.getCanonicalName());
		return alias;
	}

	public String getFieldAlias(Class type, String field) {
		AliasFields aliases = aliasFields.get(type.getCanonicalName());
		if (aliases != null) {
			String alias = aliases.getAliases().get(field);
			return alias;
		}
		return null;
	}

	public FieldNameList getOmitedFields(Class type) {
		FieldNameList omited = omitFields.get(type.getCanonicalName());
		return omited;
	}

	public AliasFields getAliasFields(Class type) {
		AliasFields aliases = aliasFields.get(type.getCanonicalName());
		return aliases;
	}

	public FieldNameList getAttributeFields(Class type) {
		FieldNameList omited = attributeFields.get(type.getCanonicalName());
		return omited;
	}

	public void addAlias(Class type, String alias) {
		classAlias.put(type.getCanonicalName(), alias);
	}

	public void addFieldAlias(Class type, String fieldName, String alias) {
		AliasFields aliases = aliasFields.get(type.getCanonicalName());
		if (aliases == null) {
			aliases = new AliasFields();
			aliasFields.put(type.getCanonicalName(), aliases);
		}
		aliases.getAliases().put(fieldName, alias);
	}

	public void addOmitedFields(Class type, String fieldName) {
		FieldNameList aliases = omitFields.get(type.getCanonicalName());
		if (aliases == null) {
			aliases = new FieldNameList();
			omitFields.put(type.getCanonicalName(), aliases);
		}
		aliases.getFieldNames().add(fieldName);
	}

	public void setAttributeField(Class type, String fieldName) {
		FieldNameList attributes = attributeFields.get(type.getCanonicalName());
		if (attributes == null) {
			attributes = new FieldNameList();
			attributeFields.put(type.getCanonicalName(), attributes);
		}
		attributes.getFieldNames().add(fieldName);
	}

	// public Map<String, FieldNameList> getOmitFields() {
	// return omitFields;
	// }
	//
	// public Map<String, AliasFields> getAliasFields() {
	// return aliasFields;
	// }
	//
	// public Map<String, FieldNameList> getAttributeFields() {
	// return attributeFields;
	// }
	//
	// public Map<String, String> getClassAlias() {
	// return classAlias;
	// }

	public FieldNameList getOmitFields(Class type) {
		return omitFields.get(type.getCanonicalName());
	}

	public String getClassAlias(Class type) {
		return classAlias.get(type.getCanonicalName());
	}

}
